package com.whfc.ms.api.fenceEdge;

import com.whfc.common.result.PageData;
import com.whfc.common.result.Result;
import com.whfc.common.result.ResultUtil;
import com.whfc.common.util.SessionAttr;
import com.whfc.env.entity.FenceEdgeDevice;
import com.whfc.env.entity.FenceEdgeDeviceDetail;
import com.whfc.fuum.entity.SysUser;
import com.whfc.ms.api.fim.service.MsFenceEdgeDeviceDetailService;
import com.whfc.ms.api.fim.service.MsFenceEdgeDeviceService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/ms/api/fenceEdgeDeviceDetail")
public class MsFenceEdgeDeviceDetailController {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private MsFenceEdgeDeviceDetailService msFenceEdgeDeviceDetailService;

    @GetMapping("/listPage")
    public Result list(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                       @RequestParam("deptId") Integer deptId,
                       @RequestParam("feId") Integer feId,
                       @RequestParam(value = "name", required = false) String name) {
        logger.info("临边防护详情列表，loginer:{},deptId:{},name:{}",
                user.getUsername(),  deptId, name);
        List<FenceEdgeDeviceDetail> list = msFenceEdgeDeviceDetailService.findList(deptId,feId, name);
        return ResultUtil.success(list);
    }

    @PostMapping("/add")
    public Result add(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                      @RequestBody FenceEdgeDeviceDetail request) {
        logger.info("临边防护详情-添加，loginer:{},request:{}", user.getUsername(), request.toString());
        msFenceEdgeDeviceDetailService.add(request);
        return ResultUtil.success();
    }

    @PostMapping("/edit")
    public Result edit(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                      @RequestBody FenceEdgeDeviceDetail request) {
        logger.info("临边防护详情-编辑，loginer:{},request:{}", user.getUsername(), request.toString());
        msFenceEdgeDeviceDetailService.edit(request);
        return ResultUtil.success();
    }

    @PostMapping("/del")
    public Result del(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                      @RequestBody FenceEdgeDeviceDetail request) {
        logger.info("临边防护详情-删除，loginer:{},request:{}", user.getUsername(), request.toString());
        msFenceEdgeDeviceDetailService.del(request);
        return ResultUtil.success();
    }
}
